2020-2021 Sunseeker Telemetry and Lighting System
cs_ex3_XT1SourcesACLK.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
60 //******************************************************************************
61 #include "driverlib.h"
62 
63 //*****************************************************************************
64 //
65 //Variable to store status of Oscillator fault flags
66 //
67 //*****************************************************************************
68 uint16_t status;
69 
70 void main (void)
71 {
72  //Stop watchdog timer
73  WDT_A_hold(WDT_A_BASE);
74 
75  //Set P1.0 to output direction
76  GPIO_setAsOutputPin(
77  GPIO_PORT_P1,
78  GPIO_PIN0
79  );
80 
81  // Configure Pins for XIN and XOUT
82  //Set P2.6 and P2.7 as Module Function Input.
83  GPIO_setAsPeripheralModuleFunctionInputPin(
84  GPIO_PORT_P2,
85  GPIO_PIN6 + GPIO_PIN7,
86  GPIO_SECONDARY_MODULE_FUNCTION
87  );
88 
89  //Set P1.1 to output ACLK
90  GPIO_setAsPeripheralModuleFunctionOutputPin(
91  GPIO_PORT_P1,
92  GPIO_PIN1,
93  GPIO_SECONDARY_MODULE_FUNCTION
94  );
95 
96  /*
97  * Disable the GPIO power-on default high-impedance mode to activate
98  * previously configured port settings
99  */
100  PMM_unlockLPM5();
101 
102  //Initializes the XT1 crystal oscillator with no timeout
103  //In case of failure, code hangs here.
104  //For time-out instead of code hang use CS_turnOnXT1LFWithTimeout()
105  CS_turnOnXT1LF(
106  CS_XT1_DRIVE_0
107  );
108 
109  CS_initClockSignal(
110  CS_ACLK,
111  CS_XT1CLK_SELECT,
112  CS_CLOCK_DIVIDER_1
113  );
114 
115  //clear all OSC fault flag
116  CS_clearAllOscFlagsWithTimeout(1000);
117 
118  //Enable oscillator fault interrupt
119  SFR_enableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
120 
121  //Enter LPM3 w/ interrupts
122  __bis_SR_register(LPM3_bits + GIE);
123 
124  //For debugger
125  __no_operation();
126 }
127 
128 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
129 #pragma vector=UNMI_VECTOR
130 __interrupt
131 #elif defined(__GNUC__)
132 __attribute__((interrupt(UNMI_VECTOR)))
133 #endif
134 void NMI_ISR(void)
135 {
136  do {
137  // If it still can't clear the oscillator fault flags after the timeout,
138  // trap and wait here.
139  status = CS_clearAllOscFlagsWithTimeout(1000);
140  } while(status != 0);
141 }
void NMI_ISR(void)
uint16_t status
void main(void)
__no_operation()